<%@ page import="com.bw.dao.GoodsDao" %>
<%@ page import="com.bw.pojo.Goods" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Asking-mac
  Date: 2022/8/1
  Time: 11:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>信息展示页</title>

    <style>
        img {
            width: 100px;
            height: 80px;
        }
    </style>
</head>
<body>
    <table>
        <tr>
            <td>id</td>
            <td>goods_name</td>
            <td>goods_price</td>
            <td>goods_des</td>
            <td>goods_num</td>
            <td>upload_people</td>
            <td>goods_img</td>
            <td>upload_time</td>
            <td>del</td>
            <td>upd</td>
        </tr>

        <% List<Goods> list = (List<Goods>) request.getAttribute("list"); %>

        <% if(list == null) {

              list = new GoodsDao().selectAll();

         } %>

        <% for(Goods li : list) {%>
                <tr>
                    <td><%=li.getId()%></td>
                    <td><%=li.getGoods_name()%></td>
                    <td><%=li.getGoods_price()%></td>
                    <td><%=li.getGoods_des()%></td>
                    <td><%=li.getGoods_num()%></td>
                    <td><%=li.getUpload_people()%></td>
                    <td><img src="<%=li.getGoods_img()%>"></td>
                    <td><%=li.getUpload_time()%></td>
                    <td><input type="button" value="删除" onclick="del(<%=li.getId()%>)"></td>
                    <td><input type="button" value="修改" onclick="upd(<%=li.getId()%>,'<%=request.getAttribute("username")%>')"></td>
                </tr>
        <% } %>

    </table>

    <input type="button" value="按价格降序排列" onclick="orderPrice()">
    <input type="button" value="按价格升序排列" onclick="orderPrice2()">

</body>

<script>
    function del(e){
    	let b = confirm("确认删除吗?");
    	if(b) {
			window.location.href = "DeleteServlet?id=" + e;
        }
    }

    function upd(e,user){
    	console.log(user);
    	window.location.href = "update.jsp?id=" + e + "&username=" + user;
    }

    function orderPrice(){
    	window.location.href = "SelectByPriceDescServlet";
    }

	function orderPrice2(){
		window.location.href = "SelectByPriceAscServlet";
	}

</script>


</html>
